package com.example.tutormanagement.controller;

import com.example.tutormanagement.pojo.Charge;
import com.example.tutormanagement.pojo.Result;
import com.example.tutormanagement.service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * &#064;Date: 23/06/14-16:12
 * &#064;Description:查找 增加 修改 无删除
 */
@RestController
@RequestMapping("/charge")
public class ChargeController {

    @Autowired
    private ChargeService chargeService;

    // get-all-data
    @GetMapping
    public Result list() {
        List<Charge> charges = chargeService.list();
        return Result.success(charges);
    }

    @GetMapping("/{id}")
    public Result select(@PathVariable String id) {
        Charge charge = chargeService.select(id);
        return Result.success(charge);
    }

    // new-data
    @PostMapping
    public Result insert(@RequestBody Charge charge) {
        chargeService.insert(charge);
        return Result.success();
    }

    // update-data
    @PutMapping("/{id}")
    public Result update(@RequestBody Charge charge, @PathVariable String id) {
        chargeService.update(charge, id);
        return Result.success();
    }
}
